package nieflash.website {
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import nieflash.utils.object;
	
	public class button extends MovieClip {
		protected var type:int = -1;
		
		private var _btn:SimpleButton;
		private var _canClick:Boolean = true;
		private var _isSprite = false;
		
		protected var _id:String = "";
		
		public function button():void {
			type = object.getObjectID(this.toString(), 1);
			
			this.addEventListener(Event.ADDED_TO_STAGE, addToStage);
			
			_btn = this.getChildByName("btn_btn") as SimpleButton;
			if (_btn != null) {
				_isSprite = false;
				_btn.addEventListener(MouseEvent.MOUSE_OVER, function() {
					if (_canClick) toOver();
				});
				_btn.addEventListener(MouseEvent.MOUSE_OUT, function() {
					if (_canClick) toOut();
				});
				_btn.addEventListener(MouseEvent.CLICK, function() {
					if (_canClick) clickFunction();
				});
			}else {
				_isSprite = true;
				this.addEventListener(MouseEvent.MOUSE_OVER, function() {
					if (_canClick) toOver();
				});
				this.addEventListener(MouseEvent.MOUSE_OUT, function() {
					if (_canClick) toOut();
				});
				this.addEventListener(MouseEvent.CLICK, function() {
					if (_canClick) clickFunction();
				});
			}
		}
		
		protected function toOver():void {
			if (!_isSprite) {
				if (currentLabel != "over") gotoAndPlay("over");
			}
		}
		
		protected function toOut():void {
			if (!_isSprite) {
				if (currentLabel != "out") gotoAndPlay("out");
			}
		}
		
		protected function clickFunction():void { };
		
		protected function addToStage(evt:Event):void {
			if (_id == movieClip.currentPage) {
				toOver();
				_canClick = false;
			}else {
				_canClick = true;
			}
		}
	}
}